package org.example.petsystem.service.impl;

import org.example.petsystem.entity.ResultBody;
import org.example.petsystem.mapper.SearchMapper;
import org.example.petsystem.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SearchServiceimpl implements SearchService {
    @Autowired
    private SearchMapper searchMapper;
    //按照商品名称进行查询
    @Override
    public ResultBody searchByName(Map<String,Object>map) {
        if(!searchMapper.searchByName(map).isEmpty())
        {
            return new ResultBody(200,"查询成功",searchMapper.searchByName(map),searchMapper.searchByName(map).size());
        }
        else if(searchMapper.searchByName(map).isEmpty())
        {
            return new ResultBody(200,"暂无商品",searchMapper.searchByName(map));
        }
        return new ResultBody(500,"查询失败",false);
    }
//    按照类别进行查询
    @Override
    public ResultBody searchByKind(Map<String,Object>map) {
        if(!searchMapper.searchByKind(map).isEmpty())
        {
            return new ResultBody(200,"查询成功",searchMapper.searchByKind(map),searchMapper.searchByKind(map).size());
        }
        else if(searchMapper.searchByKind(map).isEmpty())
        {
            return new ResultBody(200,"暂无商品",searchMapper.searchByKind(map));
        }

        return new ResultBody(500,"查询失败",false);
    }

    //当传空值时，查询所有商品
    @Override public ResultBody search() {
        List<Map<String,Object>> list=searchMapper.search();
        if(!list.isEmpty())
        {
            return new ResultBody(200,"查询成功",list,list.size());
        }
        return new ResultBody(400,"暂无商品",false);
    }

}
